//
// Created by 吴喆 on 2020/3/2.
//

#ifndef SUMMER_TIME_H
#define SUMMER_TIME_H

#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>

class CTime {
public:

    static CTime* getInstance() {
        return cTime;
    }
    //Called at the start of the main loop
    void update() {
        //Find delta time
        this->current_frame = (float) glfwGetTime();
        this->delta = this->current_frame - this->last_frame;

        //Update time
        this->time = (float) glfwGetTime();

        //Find FPS
        this->fps = 1.0f / this->delta;
//        std::cout << delta << std::endl;

        //Done
        this->frames_passed++;
        this->seconds += this->delta;
        this->last_frame = this->current_frame;
    }

    //Since all values should be read only they need getters
    float getCurrentFrame() { return this->current_frame; }

    int getFramesPassed() { return this->frames_passed; }

    float getLastFrame() { return this->last_frame; }

    float getSeconds() { return this->seconds; }

    float getDelta() { return this->delta; }

    float getTime() { return this->time; }

    float getFps() { return this->fps; }

private:
    CTime() = default;

    //Values to return
    int frames_passed = 0;
    float seconds = 0.0f;
    float delta = 0.0f;
    float time = 0.0f;
    float fps = 0.0f;
    //Calculating delta time
    float last_frame = 0.0f;
    float current_frame = 0.0f;
    static CTime* cTime;

};

#endif //SUMMER_TIME_H
